<template>
  <div id="agreement">  
   <div  style="display:flex;align-items: center;">
            <img class="top_img" src="@/assets/images/a8.png" style="width:35px;height:35px;margin-right:10px;"/>
            <div style="line-height: 40px;font-weight:bold:">协议管理</div>
     </div>
  <el-row>
        <el-col :span="24" style="text-align: right;">         
            <el-button type="primary" class="custom_color_button1" style="margin-bottom:10px;"  @click="add_but">
              <img class="custom_color_button1_img" src="@/assets/images/but_bg2.png" />添加信息
            </el-button>         
        </el-col>
  </el-row>


   <!-- 渲染数据list -->
   <agreement-list :list="list" @up_list_fun="list_fun"> </agreement-list>

  
   <el-dialog title="添加信息" :visible.sync="add_mtk"  width="800px" >
          <el-form ref="form" :model="formlist"  label-width="100px" style="width:100%;">
                <el-form-item label="标题">
                    <el-input v-model="formlist.title" placeholder="必填"></el-input>
                </el-form-item> 

                  <el-form-item label-width="100px" label="类型" >
                    <el-select  v-model="formlist.select_num" placeholder="请选择用户类别">
                        <el-option  v-for="(item,index) in select_data" :key="index" :label="item.title" :value="item.val"></el-option>
                    </el-select>
                  </el-form-item>

             <!-- 富文本选取图片 -->
                <el-form-item label="详情" style="">
                    <div style="">
                        <quill-editor class="editor"
                            v-model="formlist.content" 
                            ref="myQuillEditor" 
                            :options="editorOption" 
                            @blur="onEditorBlur($event)" @focus="onEditorFocus($event)"
                            @change="onEditorChange($event)" style="height:300px;margin-bottom:100px;">
                        </quill-editor>
                    </div>
                </el-form-item>
            <!-- 富文本选取图片 -->
            <el-form-item label="" v-show="false" >  
                <el-upload                                                
                    action="uploadUrl"  
                    :show-file-list="false"   
                    :before-upload="beforeupload"
                    :http-request="ImgUploadSectionFile">
                        <el-button slot="trigger" size="small" type="primary" id="selectImg">选取文件</el-button>
                </el-upload>
            </el-form-item>

                

         </el-form>
          <div style="text-align: center;width:80%;margin:auto;">
                  <el-button type="primary" style="width:80%;" class="custom_color_button" @click="add_but_qr">确认</el-button>
          </div>

   </el-dialog>  
      
   <div style="margin-top:20px;text-align: center;">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :page-size="10"  
        layout="prev, pager, next, jumper"
        :total="count">
      </el-pagination>
    </div>

    

      
  </div>
</template>

<script>
import toolbarOptions from '@/assets/js/quillConfig.js'
import AgreementList from '@/view/Infor/AgreementList'
export default {
  name: 'agreement',
  data () {
    return {
        list:[{"name":"ssss"}],
        page:1,
        count:0,
        add_mtk:false,
        formlist:{
            content:'',
            upfile:'',
            title:'',
            select_num:''
        },
        select_data:[],
        editorOption: {//富文本
          modules: {
            toolbar: {
              container: toolbarOptions,  // 工具栏
              handlers: {
                'image': function (value) {
                  if (value) {
                    // alert('自定义图片')
                    document.getElementById("selectImg").click();    //调用选择图片
                    
                  } else {
                   // this.quill.format('image', false);
                  }
                }
              }
            }
           }       
        },
    }
  },
 components:{
    AgreementList
  },
  created(){
    this.type_fun()
    this.list_fun()
  },
  mounted (){
    
  },
  methods: {
       type_fun(){
          this.post("/agreement/listOfType", {
             
	        }).then(res => {
     
            this.select_data = res.result
            //console.log(res,"ddd")
         })
      },

      list_fun(){
          this.post("/agreement/listOfData", {
              page:this.page, 
	        }).then(res => {
            this.count = res.result.count
            this.list = res.result.list
            console.log(res)
         })
      },
     add_but(){
         this.add_mtk = true
         this.formlist = {
            content:'',
            upfile:'',
            title:''
         }
      
     },
     add_but_qr(){
        this.post("/agreement/create", {
                title:this.formlist.title,
                content:this.formlist.content,
                type:this.formlist.select_num
            }).then(res => {

                if(res.error_code == 0){
                    this.open1(res.result,'success')  //提示框
                    this.list_fun()
                    this.add_mtk = false
                }else {
                this.open1(res.message,'warning')
            }

        })
     },
     ImgUploadSectionFile(param){//图片上传    
     },
      beforeremove(){
          return false
      },
      onEditorBlur(){ //富文本
     },
     onEditorFocus(){//富文本获得焦点事件
     },
     onEditorChange(){//富文本内容改变事件
      //console.log(this.xg_school.content)
     },
     beforeupload(file){   //重新写入上穿 需要点击确认上传与表单一起提交
           if(this.upimglx(file) == false){  //判断是否为fales
              this.upimglxtitle()  //执行弹出错误             
              return false
            }            
            this.upimgpost("/image/uploadMultiple",file).then(res => {
            this.formlist.upfile = res.result.url   
            this.formlist.content = this.formlist.content +'<img src="'+  this.urlimg + this.formlist.upfile +'"/>'

           })

          return false;
      },
 


     handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.page = val
        this.list_fun()
        console.log(`当前页: ${val}`);
      }
  }
}
</script>


<style scoped>
.avatar-uploader  {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 150px;
    height: 150px;
    line-height: 150px;
    text-align: center;
  }
  .avatar {
    width: 150px;
    height: 150px;
    display: block;
  }
</style>
